const vm = Vue.createApp({
    data() {
        return {
            blogs: []
        }
    },

    created() {
        // 页面刷新触发异步数据加载
        this.findBlogs();
    },

    methods: {
        async findBlogs() {
            // 异步加载数据返回
            var res = await  axios.get("/archives/load");
            this.blogs = res.data;
        },

        async loadMore(index) {
            // 用对象架构
            let {year,blogList,pageMap} =  this.blogs[index];
            let {pageNo:pno,pages,pageSize} = pageMap;
            // 2: 分页叠加
            let pageNo = pno * 1 + 1;
            // 3: 边界判断
            if (pageNo > pages) {
                alert("没有更多了!!!")
                return;
            }
            // 4：这里为什么要放回去，去渲染一些页面，
            this.blogs[index].pageMap.pageNo = pageNo;
            // 5:根据年份和分页去查询分页信息
            try {
                //let res = await axios.get("/archives/loadmore?year=" + year + "&pageNo=" + pageNo + "&pageSize=" + pageSize);
                let res = await axios.get("/archives/loadmore",{params:{year,pageNo,pageSize}});
                this.blogs[index].blogList = blogList.concat(res.data);
            }catch (e) {
                console.log("出错了.....")
            }
        }
    }
}).mount("#app");